package ym.ecrm.web.action.systemManagement;

import org.springframework.beans.factory.annotation.Autowired;

import ym.ecrm.core.common.util.Pager;
import ym.ecrm.core.dto.systemManagement.RoleDTO;
import ym.ecrm.core.dto.systemManagement.RoleQueryConditionDTO;
import ym.ecrm.core.service.systemManagement.ISystemService;
import ym.ecrm.web.action.base.BaseAction;

/**
 * 
 * @author Princess
 * 
 */
public class ListRoleAction extends BaseAction {

	private String roleCode;
	private String roleName;
	private String buildIn;
	private int page;
	private int limit;
	private Pager<RoleDTO> pager;
	
	@Autowired
	private ISystemService systemService;

	public String execute() {
		if((roleCode == null || roleCode.equals("")) &&
		    (roleName == null || roleName.equals("")) &&
			(buildIn == null || buildIn.equals(""))){
			pager = systemService.findRoles(page, limit);
		}
		if (roleCode != null && !roleCode.equals("")) {
			RoleQueryConditionDTO queryConditionDTO = 
					new RoleQueryConditionDTO();
			queryConditionDTO.setRoleCode(roleCode);
			pager = systemService.findRoles(queryConditionDTO, page, limit);
			return proccess();
		}
		if (roleName != null && !roleName.equals("")) {
			RoleQueryConditionDTO queryConditionDTO = 
					new RoleQueryConditionDTO();
			queryConditionDTO.setRoleName(roleName);
			pager = systemService.findRoles(queryConditionDTO, page, limit);
			return proccess();
		}
		if (buildIn != null && !buildIn.equals("")) {
			RoleQueryConditionDTO queryConditionDTO = 
					new RoleQueryConditionDTO();
			queryConditionDTO.setBuiltIn(buildIn);
			pager = systemService.findRoles(queryConditionDTO, page, limit);
			return proccess();
		}
		pager = systemService.findRoles(page, limit);
		return proccess();
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public String getSuccess() {
		return success;
	}

	public String getRoleCode() {
		return roleCode;
	}

	public void setRoleCode(String roleCode) {
		this.roleCode = roleCode;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getBuildIn() {
		return buildIn;
	}

	public void setBuildIn(String buildIn) {
		this.buildIn = buildIn;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public Pager<RoleDTO> getPager() {
		return pager;
	}

	public void setPager(Pager<RoleDTO> pager) {
		this.pager = pager;
	}

}
